package com.futonredemption.batterytest;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.CheckBox;
import android.widget.EditText;

public class BatteryTestActivity extends Activity {
	
	EditText RequestTimeEditText;
	CheckBox UseAlarmManagerCheckbox;
	CheckBox UseWakeLockCheckbox;
	Button StartServiceButton;
	Button FinishServiceButton;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        bindViews();
    }

	private void bindViews() {
		RequestTimeEditText = (EditText)findViewById(R.id.RequestTimeEditText);
		UseAlarmManagerCheckbox = (CheckBox)findViewById(R.id.UseAlarmManagerCheckbox);
		UseWakeLockCheckbox = (CheckBox)findViewById(R.id.UseWakeLockCheckbox);
		StartServiceButton = (Button)findViewById(R.id.StartServiceButton);
		FinishServiceButton = (Button)findViewById(R.id.FinishServiceButton);
		
		StartServiceButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				startBatteryWasterService();
			}
		});
		
		FinishServiceButton.setOnClickListener(new OnClickListener() {
			public void onClick(View v) {
				stopBatteryWasterService();
			}
		});
	}

	protected void stopBatteryWasterService() {
		final Intent serviceIntent = new Intent(this, BatteryWasterService.class);
		this.stopService(serviceIntent);
	}

	protected void startBatteryWasterService() {
		final int minutesBetweenPings = Integer.parseInt(RequestTimeEditText.getText().toString());
		final boolean usingAlarmManager = UseAlarmManagerCheckbox.isChecked();
		final boolean usingWakeLock = UseWakeLockCheckbox.isChecked();
		
		final Intent serviceIntent = new Intent(this, BatteryWasterService.class);
		serviceIntent.putExtra(BatteryWasterService.EXTRA_TimeBetweenPings, minutesBetweenPings);
		serviceIntent.putExtra(BatteryWasterService.EXTRA_UseAlarmManager, usingAlarmManager);
		serviceIntent.putExtra(BatteryWasterService.EXTRA_UseWakeLock, usingWakeLock);
		serviceIntent.putExtra(BatteryWasterService.EXTRA_Action, BatteryWasterService.EXTRA_Action_Start);
		this.startService(serviceIntent);
	}
	
	
}